<template>
  <div>
    <h2>用户登录</h2>
    <el-input v-model="user.username"></el-input>
    <el-input type="password" v-model="user.password"></el-input>
    <el-button @click="onLogin">登录</el-button>
  </div>
</template>

<script>
  export default {
    layout:'blank',
    data() {
      return {
        user: {
          username: "",
          password: ""
        }
      };
    },
    methods: {
      onLogin() {
        this.$store.dispatch("user/login", this.user).then(ok=>{
          if (ok) {
            const redirect = this.$route.query.redirect || '/'
            this.$router.push(redirect);
          }
        });
      }
    }
  };
</script>
